package uk.co.chrisdadswell.radioreminder;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * Created with IntelliJ IDEA.
 * User: Christian Dadswell
 * Date: 08/04/13
 * Time: 16:54
 */

/** TODO: Get this adapter working with activityDashboard to display custom row broadcast_row
 * http://www.androidhive.info/2012/02/android-custom-listview-with-image-and-text/
 */


public class adapterBroadcasts extends BaseAdapter {

    private Activity activity;
    private ArrayList<HashMap<String, String>> data;
    private static LayoutInflater inflater=null;

    public adapterBroadcasts(Activity a, ArrayList<HashMap<String, String>> d) {
        activity = a;
        data=d;
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }


    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View view, ViewGroup viewGroup) {
        View vi=view;
        if(vi==null)
            vi = inflater.inflate(R.layout.broadcast_row, null);

        TextView time = (TextView)vi.findViewById(R.id.text_row_time);
        TextView title = (TextView)vi.findViewById(R.id.text_row_schedule_title);
        TextView subtitle = (TextView)vi.findViewById(R.id.text_row_schedule_subtitle);

        HashMap<String, String> broadcasts;
        broadcasts = data.get(position);

        // Setting all values in listview
        time.setText(broadcasts.get(activityDashboard.KEY_TIME));
        title.setText(broadcasts.get(activityDashboard.KEY_TITLE));
        subtitle.setText(broadcasts.get(activityDashboard.KEY_SUBTITLE));
        return vi;
    }
}